using System;
using System.Collections.Generic;
using System.ComponentModel;
using Abs.Core.DAL.AdoNet;
using Abs.Core.Models.User;

namespace Abs.Core.Management
{
    public class UserManagement
    {
        internal UserManagement()
        {
        }

        [DataObjectMethod(DataObjectMethodType.Insert)]
        public bool Create(string email, string password, 
                           string name, int roleId = (int) RoleEnum.User)
        {
            using(var userRepository = new UserRepository())
            {
                return userRepository.Create(new User
                                             {
                                                 Email = email,
                                                 Password = password,
                                                 Name = name,
                                                 RoleId = roleId
                                             });
            }//end of using(var userRepository = new UserRepository)
        }//end of public bool Create(User item)

        [DataObjectMethod(DataObjectMethodType.Fill)]
        public IList<User> SelectAll()
        {
            using(var userRepository = new UserRepository())
            {
                return userRepository.SelectAll();
            }//end of using(var userRepository = new UserRepository())
        }//end of public IList<User> SelectAll()
        
        [DataObjectMethod(DataObjectMethodType.Select)]
        public User Select(string email)
        {
            using (var userRepository = new UserRepository())
            {
                return userRepository.Select(new object[]{email});
            }//end of using(var userRepository = new UserRepository())
        }//end of public User Select(object[] id)

        [DataObjectMethod(DataObjectMethodType.Update)]
        public bool Update(string email, 
                           string name, 
                           int roleId = (int) RoleEnum.User)
        {
            using (var userRepository = new UserRepository())
            {
                return userRepository.Update(new User
                                             {
                                                 Email = email,
                                                 Name = name,
                                                 RoleId = roleId
                                             });
            }//end of using(var userRepository = new UserRepository())
        }//end of public bool Update(User item)

        [DataObjectMethod(DataObjectMethodType.Delete)]
        public bool Delete(string email)
        {
            using (var userRepository = new UserRepository())
            {
                return userRepository.Delete(new object[] { email });
            }//end of using(var userRepository = new UserRepository())
        }//end of public bool Delete(object[] id)

        public bool ChangePassword(User item)
        {
            throw new NotImplementedException();
        }//end of public bool ChangePassword(User item)

        public User LogIn(string email, string password)
        {
            using(var userRepository = new UserRepository())
            {
                return userRepository.LogIn(new LogIn
                                            {
                                                Email = email,
                                                Password = password
                                            });
            }//end of using(var userRepository = new UserRepository())
        }//end of public User LogIn(LogIn item)
    }//end of public class UserManagement 
}//end of namespace ABS.Logic